package com.woniuxy.sddfp.system.controller;

import com.woniuxy.sddfp.common.model.dto.user.LoginDto;
import com.woniuxy.sddfp.common.model.dto.user.UserRegisterDto;
import com.woniuxy.sddfp.common.model.vo.user.LoginVo;
import com.woniuxy.sddfp.common.result.Result;
import com.woniuxy.sddfp.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/test")
    public String test(){
        return "hello system";
    }

    @GetMapping("/test1")
    public Result test1(){
        return Result.ok("中彩票 3000w");
    }

    @GetMapping("/test2")
    public Result test2(){

        int a = 1/0;

        return Result.ok("中彩票 4000w");
    }

    /**
     * 用户注册
     * @Valid  对 userRegisterDto 进行 数据校验
     */
    @PostMapping("/regist")
    public Result regist(@RequestBody @Valid UserRegisterDto userRegisterDto){

        //创建分支

        //调用 service 注册方法

        Result result = userService.register(userRegisterDto);

        return result;
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }

}
